import 'package:flutter/material.dart';
import 'tabs/HomePage.dart';
import 'tabs/SettingPage.dart';
import 'tabs/CategoryPage.dart';

// 自定有状态组件Tab
class Tabs extends StatefulWidget {
  final index;
  Tabs({Key key, this.index = 0}) : super(key: key);

  @override
  _TabsState createState() => _TabsState(this.index);
}

class _TabsState extends State<Tabs> {
  int _currentIndex;

  _TabsState(index) {
    this._currentIndex = index;
  }

  List pageList = [HomePage(), CategoryPage(), SettingPage()];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("标题"),
      ),
      floatingActionButton: Container(
        width: 80,
        height: 80,
        padding: EdgeInsets.all(8),
        margin: EdgeInsets.only(top: 5),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(40), color: Colors.white),
        child: FloatingActionButton(
          child: Icon(
            Icons.add,
            // size: 20,
            // color: Colors.white,
          ),
          onPressed: () {
            print("浮动按钮");
            setState(() {
              this._currentIndex = 1;
            });
          },
          backgroundColor:
              this._currentIndex == 1 ? Colors.blue : Colors.orange,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: this.pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index) {
          setState(() {
            this._currentIndex = index;
          });
        },
        iconSize: 30.0, //icon大小
        fixedColor: Colors.orange, //选中颜色
        type: BottomNavigationBarType.fixed, //超过三个以上需要设置该属性
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首页")),
          BottomNavigationBarItem(
              icon: Icon(Icons.category), title: Text("分类")),
          BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text("设置"))
        ],
      ),
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                    child: UserAccountsDrawerHeader(
                  accountName: Text("大黄"),
                  accountEmail: Text("1871079077@163.com"),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: NetworkImage(
                        "https://www.itying.com/images/flutter/3.png"),
                  ),
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage(
                              "https://www.itying.com/images/flutter/3.png"),
                          fit: BoxFit.cover)),
                )
                    //     DrawerHeader( 方式一
                    //   child: Text("我是头"),
                    //   decoration: BoxDecoration(
                    //       // color: Colors.blue
                    //       image: DecorationImage(
                    //           image: NetworkImage(
                    //               "https://www.itying.com/images/flutter/3.png"),
                    //           fit: BoxFit.cover)),
                    // )
                    )
              ],
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.home)),
              title: Text("我的空间"),
            ),
            Divider(),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.person)),
              title: Text("用户中心"),
              onTap: () {
                Navigator.of(context).pop(); //隐藏侧边栏
                Navigator.pushNamed(context, "/drawerUser");
              },
            ),
            Divider(),
            ListTile(
                leading: CircleAvatar(child: Icon(Icons.settings)),
                title: Text("设置中心"))
          ],
        ),
      ),
      endDrawer: Drawer(
        child: Text("右边"),
      ),
    );
  }
}
